﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 10/04/2009
// Time: 0:35
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Drawing;
using System.Windows.Forms;

namespace csharp.rad.general.entries
{
	/// <summary>
	/// Description of frmRegisterProductGroup.
	/// </summary>
	public partial class frmRegisterProductGroup : common.RegisterTemplate
	{
		ProductGroup productGroup = new ProductGroup();
		ProductGroups listProductGroup = new ProductGroups();
		
		public frmRegisterProductGroup()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		#region overrided methods
		
			protected override void newEvent()
			{
				productGroup.clear();
				txtName.Focus();
			}
			
			/// <summary>
			/// Set data from edits to class
			/// </summary>
			protected override void setClass()
			{
				productGroup.name = txtName.Text;
				productGroup.companyId = Information.companyId;
			}
			
			/// <summary>
			/// Set data from class to edits
			/// </summary>
			protected override void setEdits()
			{
				productGroup.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();
				
				if (productGroup.get())
				{
					txtName.Text = productGroup.name;
				}
			}
			
			/// <summary>
			/// Fill the DataGridView
			/// </summary>
			protected override void fillDataGridView()
			{
				int tam;
				listProductGroup.fillList();
				
				tam = listProductGroup.count();
				dgvMain.Rows.Clear();
				for (int i=0; i < tam; i++)
				{
					dgvMain.Rows.Add(new String[] {listProductGroup.get(i).id, listProductGroup.get(i).name});
				}				
			}
			
			/// <summary>
			/// Find the object of search
			/// </summary>
			protected override void find()
			{
				common.Util.searchInGrid(dgvMain, "name", txtSearch.Text);
			}		
			
		   /// <summary>
		   /// Save the register in the database.
		   /// </summary>
		   /// <returns>bool - true if the register was saved sucessful, false case not.</returns>	
		   protected override bool save()
		   {
		   	return productGroup.save();
		   }
		   
		   /// <summary>
		   /// Update the register in the database
		   /// </summary>
		   /// <returns>bool - true if the register was updated sucessful, false case not.</returns>
		   protected override bool update()
		   {   
		   	return productGroup.update();
		   }
		   
		   /// <summary>
		   /// Delete the register in the database.
		   /// </summary>
		   /// <returns>bool - true if the register was deleted sucessful, false case not.</returns>
		   protected override bool delete()
		   {
		   	productGroup.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();
		   	return productGroup.delete();
		   }
		   
		   /// <summary>
		   /// Method call in initialization
		   /// </summary>
		   protected override void init()
		   {
		   	DataGridViewTextBoxColumn id = new DataGridViewTextBoxColumn();
		   	DataGridViewTextBoxColumn name = new DataGridViewTextBoxColumn();
		   	
		   	id.Name = "id";
		   	id.Visible = false;
		   	
		   	name.Name = "name";
		   	name.HeaderText = "Nome";
		   	name.Width = 300;
		   	
		   	dgvMain.Columns.AddRange(new DataGridViewColumn[] {id, name});

		   }
		#endregion		
	}
}
